package com.sams.controller;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.zip.ZipOutputStream;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;
import com.sams.entity.Baseinfo;
import com.sams.entity.CountrySub;
import com.sams.entity.DataTotal;
import com.sams.entity.DataUp;
import com.sams.entity.GovSub;
import com.sams.entity.Processmanage;
import com.sams.entity.SchoolSub;
import com.sams.entity.SocietySub;
import com.sams.entity.SpotUpload;
import com.sams.entity.User;
import com.sams.service.BaseInfoService;
import com.sams.service.CountrySubService;
import com.sams.service.DataTotalService;
import com.sams.util.ZipFileUtil;

@RequestMapping("/datatotal")
@Controller
public class DatatTotalController {
	
	@Autowired
	private DataTotalService service;
	@Autowired
	private BaseInfoService baseInfoService;
	//国家资助 归档统计
	@Autowired
	private CountrySubService countrySubService;
	
	@Value("#{prop.imagePath}")
	private String uploadPath;
	/**
	 * 
	 * @param currentPage
	 * @param request
	 * @param schid  学校id
	 * @param term  学期
	 * @param level  学段
	 * @param project  项目名
	 * @param beginDate 开始时间
	 * @param endDate  结束时间
	 * @param model
	 * @return
	 * @throws ParseException 
	 */
	@RequestMapping("/listcountrysub")
	public String listCountrySub(Integer currentPage ,HttpServletRequest request,
			String beginDate,String endDate,String project,String term,
			Integer zid, String schoolname ,String name,String idcard,
			Model model) throws ParseException {
		if(currentPage==null || currentPage==0) {
			currentPage=1;
		}
		User user =  (User)request.getSession().getAttribute("user");
		if(user==null) {
			model.addAttribute("error", "会话过期，请重新登录");
			return "error";
		}
		SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy-MM-dd");
		 //按条件查询
		DataTotal dataTotal = new DataTotal();
		if(beginDate!=null && !beginDate.equals("")) {
			
			dataTotal.setBeginDate(sdFormat.parse(beginDate));
		}
		if(endDate!=null && !endDate.equals("")) {
			dataTotal.setEndDate(sdFormat.parse(endDate));
		}
		if(project!=null && !project.equals("")) {
			dataTotal.setProject(project);
		}
		if(term!=null && !term.equals("")) {
			dataTotal.setTerm(term);
		}
		if(zid!=null && !zid.toString().equals("0")) {
			dataTotal.setZid(zid);
		}
		if(schoolname!=null && !schoolname.equals("")) {
			dataTotal.setSchoolname(schoolname);
		}
		if(name!=null && !name.equals("")) {
			dataTotal.setName(name);
		}
		if(idcard!=null && !idcard.equals("")) {
			dataTotal.setIdcard(idcard);
		}
		
		//如果当前用户 ==1  查询当前自己的数据  且状态=1
		if(user.getRoleid()==1) {
			dataTotal.setUid(user.getId());   
		}else if(user.getRoleid()==2) {//镇级别   ？？
			dataTotal.setZid(user.getZid());
		}
		dataTotal.setStatus(4);//查询归档状态的数据
		
		PageInfo<CountrySub> pageInfo= service.selectCountrySub(currentPage, dataTotal);
		
		System.out.println(pageInfo.getList());
		model.addAttribute("pageInfo",pageInfo);
		model.addAttribute("dataTotal", dataTotal);
		 
		return "datatotalCountrySub";
	}
	
	//查询数据的导出   
	
	// 下载学生的档案信息（批量下载图片，打包成zip）
	
	//查看学生信息的详情   ok
	
	//根据权限查询 所有乡镇
	@ResponseBody
	@RequestMapping("/getAllZhen")
	public List<Baseinfo> selectAllZhen(HttpServletRequest request){
		User user =  (User)request.getSession().getAttribute("user");
		if(user==null) {
			 
			return null;
		}
		if(user.getRoleid()==1 ||user.getRoleid()==2) {
			 //根据用户的 镇id 查询 并返回
			return baseInfoService.findById(user.getZid());
		}else { 
			return service.selectAllZhen();
		}
	}
	
	
//	@ResponseBody
	@RequestMapping("/exportCountryExcel")
	public void dowm(HttpServletRequest request,HttpServletResponse response,
			String beginDate,String endDate,String project,String term,
			Integer zid, String schoolname ,String name,String idcard) throws ParseException{
		
		User user =  (User)request.getSession().getAttribute("user");
		if(user==null) {
			//model.addAttribute("error", "会话过期，请重新登录");
		//	return "会话过期，请重新登录";
		}
		SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy-MM-dd");
		 //按条件查询
		DataTotal dataTotal = new DataTotal();
		if(beginDate!=null && !beginDate.equals("")) {
			
			dataTotal.setBeginDate(sdFormat.parse(beginDate));
		}
		if(endDate!=null && !endDate.equals("")) {
			dataTotal.setEndDate(sdFormat.parse(endDate));
		}
		if(project!=null && !project.equals("")) {
			dataTotal.setProject(project);
		}
		if(term!=null && !term.equals("")) {
			dataTotal.setTerm(term);
		}
		if(zid!=null && !zid.toString().equals("0")) {
			dataTotal.setZid(zid);
		}
		if(schoolname!=null && !schoolname.equals("")) {
			dataTotal.setSchoolname(schoolname);
		}
		if(name!=null && !name.equals("")) {
			dataTotal.setName(name);
		}
		if(idcard!=null && !idcard.equals("")) {
			dataTotal.setIdcard(idcard);
		}
		
		//如果当前用户 ==1  查询当前自己的数据  且状态=1
		if(user.getRoleid()==1) {
			dataTotal.setUid(user.getId());   
		}else if(user.getRoleid()==2) {//镇级别   ？？
			dataTotal.setZid(user.getZid());
		}
		dataTotal.setStatus(4);//查询归档状态的数据
		
		
		//开始导出数据 
	     response.setContentType("application/binary;charset=UTF-8");
          try{
              ServletOutputStream out=response.getOutputStream();
              
                  //设置文件头：最后一个参数是设置下载文件名(这里我们叫：张三.pdf)
              response.setHeader("Content-Disposition", "attachment;fileName=国家资助档案.xls");
           
              String[] titles = { "序号", "受助项目", "学校", "姓名" ,"性别","年级","班级",
            		  "身份证号","学籍号","受助类别","详细原因","省","市","县",
            		  "镇","村(社区、街道)","组(路)","家长地址","家长姓名","与学生关系","联系电话"
            		  ,"银行卡或存折号", "银行名称","资助金额或免学费金额(元"}; 
               service.export(titles, out,dataTotal);      
          //    return "success";
          } catch(Exception e){
              e.printStackTrace();
         //     return "导出信息失败";
          }
      
	}
	/**
	 * 根据 国家资助的id  批量下载学生档案图片
	 * @param id
	 * @param request
	 * @param response
	 * @return
	 * @throws ServletException
	 * @throws IOException
	 */
	@RequestMapping(value = "/downloadCountroyZip")
    public String downloadFiles(Integer id, HttpServletRequest request, HttpServletResponse response,Model model)
            throws ServletException, IOException {
//        List<File> files = new ArrayList<File>();
//        File Allfile = new File(request.getSession().getServletContext().getRealPath("/") + "upload/");
//        if (Allfile.exists()) {
//            File[] fileArr = Allfile.listFiles();
//            for (File file2 : fileArr) {
//                files.add(file2);
//            }
//        }
		//存放所有需要下载的文件
		 List<File> files = new ArrayList<File>();
		CountrySub countrySub = countrySubService.findById(id);
		File applyfile = new File(uploadPath+File.separator+countrySub.getApplyfile());
		if(applyfile.exists()) {
			files.add(applyfile);
		}
		File apply2file = new File(uploadPath+File.separator+countrySub.getApply2file());
		if(apply2file.exists()) {
			files.add(apply2file);
		}
		File apply3file = new File(uploadPath+File.separator+countrySub.getApply3file());
		if(apply3file.exists()) {
			files.add(apply3file);
		}
		File idcardfile = new File(uploadPath+File.separator+countrySub.getIdcardfile());
		if(idcardfile.exists()) {
			files.add(idcardfile);
		}
		File idcard2file = new File(uploadPath+File.separator+countrySub.getIdcard2file());
		if(idcard2file.exists()) {
			files.add(idcard2file);
		}
		File stufile = new File(uploadPath+File.separator+countrySub.getStufile());
		if(stufile.exists()) {
			files.add(stufile);
		}
		File addressfile = new File(uploadPath+File.separator+countrySub.getAddressfile());
		if(addressfile.exists()) {
			files.add(addressfile);
		}
		File address2file = new File(uploadPath+File.separator+countrySub.getAddress2file());
		if(address2file.exists()) {
			files.add(address2file);
		}
		File bankfile = new File(uploadPath+File.separator+countrySub.getBankfile());
		if(bankfile.exists()) {
			files.add(bankfile);
		}
		if(files.size()==0) {
			model.addAttribute("error", "没有检索到该学生档案，请联系系统管理员");
			return "error";
		}
		
        String fileName = UUID.randomUUID().toString() + ".zip";
        // 在服务器端创建打包下载的临时文件
        String outFilePath = request.getSession().getServletContext().getRealPath("/") + "upload/";
 
        File fileZip = new File(outFilePath + fileName);
        // 文件输出流
        FileOutputStream outStream = new FileOutputStream(fileZip);
        // 压缩流
        ZipOutputStream toClient = new ZipOutputStream(outStream);
    //  toClient.setEncoding("gbk");
        ZipFileUtil.zipFile(files, toClient);
        toClient.close();
        outStream.close();
        //下载，并删除服务器的文件
        ZipFileUtil.downloadFile(fileZip, response, true);
        return null;
    }
 
	@RequestMapping("/listgovsub")
	public String listGovSub(Integer currentPage ,HttpServletRequest request,
			String beginDate,String endDate,String subname,String term,
			Integer zid, String schoolname ,String name,String idcard,
			Model model) throws ParseException {
		if(currentPage==null || currentPage==0) {
			currentPage=1;
		}
		User user =  (User)request.getSession().getAttribute("user");
		if(user==null) {
			model.addAttribute("error", "会话过期，请重新登录");
			return "error";
		}
		SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy-MM-dd");
		 //按条件查询
		DataTotal dataTotal = new DataTotal();
		if(beginDate!=null && !beginDate.equals("")) {
			
			dataTotal.setBeginDate(sdFormat.parse(beginDate));
		}
		if(endDate!=null && !endDate.equals("")) {
			dataTotal.setEndDate(sdFormat.parse(endDate));
		}
		if(subname!=null && !subname.equals("")) {
			dataTotal.setProject(subname);
		}
		if(term!=null && !term.equals("")) {
			dataTotal.setTerm(term);
		}
		if(zid!=null && !zid.toString().equals("0")) {
			dataTotal.setZid(zid);
		}
		if(schoolname!=null && !schoolname.equals("")) {
			dataTotal.setSchoolname(schoolname);
		}
		if(name!=null && !name.equals("")) {
			dataTotal.setName(name);
		}
		if(idcard!=null && !idcard.equals("")) {
			dataTotal.setIdcard(idcard);
		}
		
		//如果当前用户 ==1  查询当前自己的数据  且状态=1
		if(user.getRoleid()==1) {
			dataTotal.setUid(user.getId());   
		}else if(user.getRoleid()==2) {//镇级别   ？？
			dataTotal.setZid(user.getZid());
		}
		dataTotal.setStatus(4);//查询归档状态的数据
		
		PageInfo<GovSub> pageInfo= service.selectGovSub(currentPage, dataTotal);
		
		System.out.println(pageInfo.getList());
		model.addAttribute("pageInfo",pageInfo);
		model.addAttribute("dataTotal", dataTotal);
		 
		return "datatotalGovSub";
	}
	
	@RequestMapping("/exportGovExcel")
	public void dowmGov(HttpServletRequest request,HttpServletResponse response,
			String beginDate,String endDate,String project,String term,
			Integer zid, String schoolname ,String name,String idcard) throws ParseException{
		
		User user =  (User)request.getSession().getAttribute("user");
		if(user==null) {
			//model.addAttribute("error", "会话过期，请重新登录");
		//	return "会话过期，请重新登录";
		}
		SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy-MM-dd");
		 //按条件查询
		DataTotal dataTotal = new DataTotal();
		if(beginDate!=null && !beginDate.equals("")) {
			
			dataTotal.setBeginDate(sdFormat.parse(beginDate));
		}
		if(endDate!=null && !endDate.equals("")) {
			dataTotal.setEndDate(sdFormat.parse(endDate));
		}
		if(project!=null && !project.equals("")) {
			dataTotal.setProject(project);
		}
		if(term!=null && !term.equals("")) {
			dataTotal.setTerm(term);
		}
		if(zid!=null && !zid.toString().equals("0")) {
			dataTotal.setZid(zid);
		}
		if(schoolname!=null && !schoolname.equals("")) {
			dataTotal.setSchoolname(schoolname);
		}
		if(name!=null && !name.equals("")) {
			dataTotal.setName(name);
		}
		if(idcard!=null && !idcard.equals("")) {
			dataTotal.setIdcard(idcard);
		}
		
		//如果当前用户 ==1  查询当前自己的数据  且状态=1
		if(user.getRoleid()==1) {
			dataTotal.setUid(user.getId());   
		}else if(user.getRoleid()==2) {//镇级别   ？？
			dataTotal.setZid(user.getZid());
		}
		dataTotal.setStatus(4);//查询归档状态的数据
		
		
		//开始导出数据 
	     response.setContentType("application/binary;charset=UTF-8");
          try{
              ServletOutputStream out=response.getOutputStream();
              
                  //设置文件头：最后一个参数是设置下载文件名(这里我们叫：张三.pdf)
              response.setHeader("Content-Disposition", "attachment;fileName=国家资助档案.xls");
           
              String[] titles = {"序号","学生姓名","	学籍号","身份证件类型","身份证件号","性别"
            		  ,"出生日期","年份","学年","学期","资助名称","资助金额","发放日期","发放人"}; 
               service.exportGovSub(titles, out,dataTotal);      
        
          } catch(Exception e){
              e.printStackTrace();
        
          }
      
	}
	
	@RequestMapping("/listschoolsub")
	public String listSchoolSub(Integer currentPage ,HttpServletRequest request,
			String beginDate,String endDate,String subname,String term,
			Integer zid, String schoolname ,String name,String idcard,
			Model model) throws ParseException {
		if(currentPage==null || currentPage==0) {
			currentPage=1;
		}
		User user =  (User)request.getSession().getAttribute("user");
		if(user==null) {
			model.addAttribute("error", "会话过期，请重新登录");
			return "error";
		}
		SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy-MM-dd");
		 //按条件查询
		DataTotal dataTotal = new DataTotal();
		if(beginDate!=null && !beginDate.equals("")) {
			
			dataTotal.setBeginDate(sdFormat.parse(beginDate));
		}
		if(endDate!=null && !endDate.equals("")) {
			dataTotal.setEndDate(sdFormat.parse(endDate));
		}
		if(subname!=null && !subname.equals("")) {
			dataTotal.setProject(subname);
		}
		if(term!=null && !term.equals("")) {
			dataTotal.setTerm(term);
		}
		if(zid!=null && !zid.toString().equals("0")) {
			dataTotal.setZid(zid);
		}
		if(schoolname!=null && !schoolname.equals("")) {
			dataTotal.setSchoolname(schoolname);
		}
		if(name!=null && !name.equals("")) {
			dataTotal.setName(name);
		}
		if(idcard!=null && !idcard.equals("")) {
			dataTotal.setIdcard(idcard);
		}
		
		//如果当前用户 ==1  查询当前自己的数据  且状态=1
		if(user.getRoleid()==1) {
			dataTotal.setUid(user.getId());   
		}else if(user.getRoleid()==2) {//镇级别   ？？
			dataTotal.setZid(user.getZid());
		}
		dataTotal.setStatus(4);//查询归档状态的数据
		
		PageInfo<SchoolSub> pageInfo= service.selectSchoolSub(currentPage, dataTotal);
		
		System.out.println(pageInfo.getList());
		model.addAttribute("pageInfo",pageInfo);
		model.addAttribute("dataTotal", dataTotal);
		 
		return "datatotalSchoolSub";
	}
	
	@RequestMapping("/exportSchoolExcel")
	public void dowmSchool(HttpServletRequest request,HttpServletResponse response,
			String beginDate,String endDate,String project,String term,
			Integer zid, String schoolname ,String name,String idcard) throws ParseException{
		
		User user =  (User)request.getSession().getAttribute("user");
		if(user==null) {
			//model.addAttribute("error", "会话过期，请重新登录");
		//	return "会话过期，请重新登录";
		}
		SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy-MM-dd");
		 //按条件查询
		DataTotal dataTotal = new DataTotal();
		if(beginDate!=null && !beginDate.equals("")) {
			
			dataTotal.setBeginDate(sdFormat.parse(beginDate));
		}
		if(endDate!=null && !endDate.equals("")) {
			dataTotal.setEndDate(sdFormat.parse(endDate));
		}
		if(project!=null && !project.equals("")) {
			dataTotal.setProject(project);
		}
		if(term!=null && !term.equals("")) {
			dataTotal.setTerm(term);
		}
		if(zid!=null && !zid.toString().equals("0")) {
			dataTotal.setZid(zid);
		}
		if(schoolname!=null && !schoolname.equals("")) {
			dataTotal.setSchoolname(schoolname);
		}
		if(name!=null && !name.equals("")) {
			dataTotal.setName(name);
		}
		if(idcard!=null && !idcard.equals("")) {
			dataTotal.setIdcard(idcard);
		}
		
		//如果当前用户 ==1  查询当前自己的数据  且状态=1
		if(user.getRoleid()==1) {
			dataTotal.setUid(user.getId());   
		}else if(user.getRoleid()==2) {//镇级别   ？？
			dataTotal.setZid(user.getZid());
		}
		dataTotal.setStatus(4);//查询归档状态的数据
		
		
		//开始导出数据 
	     response.setContentType("application/binary;charset=UTF-8");
          try{
              ServletOutputStream out=response.getOutputStream();
              
                  //设置文件头：最后一个参数是设置下载文件名(这里我们叫：张三.pdf)
              response.setHeader("Content-Disposition", "attachment;fileName=学校资助档案.xls");
           
              String[] titles = {"序号","学生姓名","	学籍号","身份证件类型","身份证件号","性别"
            		  ,"出生日期","年份","学年","学期","资助名称","资助金额","发放日期","发放人"}; 
               service.exportSchoolSub(titles, out,dataTotal);      
        
          } catch(Exception e){
              e.printStackTrace();
        
          }
      
	}
	
	@RequestMapping("/listsocietysub")
	public String listSocietySub(Integer currentPage ,HttpServletRequest request,
			String beginDate,String endDate,String subname,String term,
			Integer zid, String schoolname ,String name,String idcard,
			Model model) throws ParseException {
		if(currentPage==null || currentPage==0) {
			currentPage=1;
		}
		User user =  (User)request.getSession().getAttribute("user");
		if(user==null) {
			model.addAttribute("error", "会话过期，请重新登录");
			return "error";
		}
		SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy-MM-dd");
		 //按条件查询
		DataTotal dataTotal = new DataTotal();
		if(beginDate!=null && !beginDate.equals("")) {
			
			dataTotal.setBeginDate(sdFormat.parse(beginDate));
		}
		if(endDate!=null && !endDate.equals("")) {
			dataTotal.setEndDate(sdFormat.parse(endDate));
		}
		if(subname!=null && !subname.equals("")) {
			dataTotal.setProject(subname);
		}
		if(term!=null && !term.equals("")) {
			dataTotal.setTerm(term);
		}
		if(zid!=null && !zid.toString().equals("0")) {
			dataTotal.setZid(zid);
		}
		if(schoolname!=null && !schoolname.equals("")) {
			dataTotal.setSchoolname(schoolname);
		}
		if(name!=null && !name.equals("")) {
			dataTotal.setName(name);
		}
		if(idcard!=null && !idcard.equals("")) {
			dataTotal.setIdcard(idcard);
		}
		
		//如果当前用户 ==1  查询当前自己的数据  且状态=1
		if(user.getRoleid()==1) {
			dataTotal.setUid(user.getId());   
		}else if(user.getRoleid()==2) {//镇级别   ？？
			dataTotal.setZid(user.getZid());
		}
		dataTotal.setStatus(4);//查询归档状态的数据
		
		PageInfo<SocietySub> pageInfo= service.selectSocietySub(currentPage, dataTotal);
		
		System.out.println(pageInfo.getList());
		model.addAttribute("pageInfo",pageInfo);
		model.addAttribute("dataTotal", dataTotal);
		 
		return "datatotalSocietySub";
	}
	
	@RequestMapping("/exportSocietyExcel")
	public void dowmSociety(HttpServletRequest request,HttpServletResponse response,
			String beginDate,String endDate,String project,String term,
			Integer zid, String schoolname ,String name,String idcard) throws ParseException{
		
		User user =  (User)request.getSession().getAttribute("user");
		if(user==null) {
			//model.addAttribute("error", "会话过期，请重新登录");
		//	return "会话过期，请重新登录";
		}
		SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy-MM-dd");
		 //按条件查询
		DataTotal dataTotal = new DataTotal();
		if(beginDate!=null && !beginDate.equals("")) {
			
			dataTotal.setBeginDate(sdFormat.parse(beginDate));
		}
		if(endDate!=null && !endDate.equals("")) {
			dataTotal.setEndDate(sdFormat.parse(endDate));
		}
		if(project!=null && !project.equals("")) {
			dataTotal.setProject(project);
		}
		if(term!=null && !term.equals("")) {
			dataTotal.setTerm(term);
		}
		if(zid!=null && !zid.toString().equals("0")) {
			dataTotal.setZid(zid);
		}
		if(schoolname!=null && !schoolname.equals("")) {
			dataTotal.setSchoolname(schoolname);
		}
		if(name!=null && !name.equals("")) {
			dataTotal.setName(name);
		}
		if(idcard!=null && !idcard.equals("")) {
			dataTotal.setIdcard(idcard);
		}
		
		//如果当前用户 ==1  查询当前自己的数据  且状态=1
		if(user.getRoleid()==1) {
			dataTotal.setUid(user.getId());   
		}else if(user.getRoleid()==2) {//镇级别   ？？
			dataTotal.setZid(user.getZid());
		}
		dataTotal.setStatus(4);//查询归档状态的数据
		
		
		//开始导出数据 
	     response.setContentType("application/binary;charset=UTF-8");
          try{
              ServletOutputStream out=response.getOutputStream();
              
                  //设置文件头：最后一个参数是设置下载文件名(这里我们叫：张三.pdf)
              response.setHeader("Content-Disposition", "attachment;fileName=社会资助档案.xls");
           
              String[] titles = {"序号","学生姓名","	学籍号","身份证件类型","身份证件号","性别"
            		  ,"出生日期","年份","学年","学期","资助名称","资助金额","发放日期","发放人"}; 
               service.exportSocietySub(titles, out,dataTotal);      
        
          } catch(Exception e){
              e.printStackTrace();
        
          }
      
	}
	
	
	@RequestMapping("/listprocess")
	public String listprocess(Integer currentPage ,HttpServletRequest request,
			String beginDate,String endDate,
			Integer zid, String schoolname ,
			Model model) throws ParseException {
		if(currentPage==null || currentPage==0) {
			currentPage=1;
		}
		User user =  (User)request.getSession().getAttribute("user");
		if(user==null) {
			model.addAttribute("error", "会话过期，请重新登录");
			return "error";
		}
		SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy-MM-dd");
		 //按条件查询
		DataTotal dataTotal = new DataTotal();
		if(beginDate!=null && !beginDate.equals("")) {
			
			dataTotal.setBeginDate(sdFormat.parse(beginDate));
		}
		if(endDate!=null && !endDate.equals("")) {
			dataTotal.setEndDate(sdFormat.parse(endDate));
		}
		 
		if(zid!=null && !zid.toString().equals("0")) {
			dataTotal.setZid(zid);
		}
		if(schoolname!=null && !schoolname.equals("")) {
			dataTotal.setSchoolname(schoolname);
		}
		 
		
		//如果当前用户 ==1  查询当前自己的数据  且状态=1
		if(user.getRoleid()==1) {
			dataTotal.setUid(user.getId());   
		}else if(user.getRoleid()==2) {//镇级别   ？？
			dataTotal.setZid(user.getZid());
		}
		dataTotal.setStatus(4);//查询归档状态的数据
		
		PageInfo<Processmanage> pageInfo= service.selectProcess(currentPage, dataTotal);
		
		System.out.println(pageInfo.getList());
		model.addAttribute("pageInfo",pageInfo);
		model.addAttribute("dataTotal", dataTotal);
		 
		return "datatotalProcess";
	}
	
	@RequestMapping("/listspot")
	public String listspot(Integer currentPage ,HttpServletRequest request,
			String beginDate,String endDate,
			Integer zid, String schoolname ,
			Model model) throws ParseException {
		if(currentPage==null || currentPage==0) {
			currentPage=1;
		}
		User user =  (User)request.getSession().getAttribute("user");
		if(user==null) {
			model.addAttribute("error", "会话过期，请重新登录");
			return "error";
		}
		SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy-MM-dd");
		 //按条件查询
		DataTotal dataTotal = new DataTotal();
		if(beginDate!=null && !beginDate.equals("")) {
			
			dataTotal.setBeginDate(sdFormat.parse(beginDate));
		}
		if(endDate!=null && !endDate.equals("")) {
			dataTotal.setEndDate(sdFormat.parse(endDate));
		}
		 
		if(zid!=null && !zid.toString().equals("0")) {
			dataTotal.setZid(zid);
		}
		if(schoolname!=null && !schoolname.equals("")) {
			dataTotal.setSchoolname(schoolname);
		}
		 
		
		//如果当前用户 ==1  查询当前自己的数据  且状态=1
		if(user.getRoleid()==1) {
			dataTotal.setUid(user.getId());   
		}else if(user.getRoleid()==2) {//镇级别   ？？
			dataTotal.setZid(user.getZid());
		}
		dataTotal.setStatus(4);//查询归档状态的数据
		
		PageInfo<SpotUpload> pageInfo= service.selectSpotUpload(currentPage, dataTotal);
		
		System.out.println(pageInfo.getList());
		model.addAttribute("pageInfo",pageInfo);
		model.addAttribute("dataTotal", dataTotal);
		 
		return "datatotalSpotUpload";
	}
}
